package ${package}.${moduleName}.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.RequestMapping;
import ${package}.${moduleName}.entity.${ClassName}Entity;
import ${package}.${moduleName}.service.${ClassName}Service;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.base.bean.ResultBean;
import com.base.controller.BaseController;
import com.base.page.entity.Page;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description: <#if tableComment!?length gt 0>${tableComment}</#if>
 * @Author: ${author}
 * @Version: ${version}
 * @Date: ${datetime}
 */
@RestController
@RequestMapping("/${modulePath}/${modulePathTail}")
public class ${ClassName}Controller extends BaseController {

    @Resource
    private ${ClassName}Service ${className}Service; //<#if tableComment!?length gt 0>注入 “${tableComment}” service</#if>

    private final Logger log = LoggerFactory.getLogger(${ClassName}Controller.class);

    /**
     * @Description: 保存数据
     * @Author: ${author}
     * @Params: [${className}Entity, request]
     * @Return: void
     * @Date: ${datetime}
     */
    @RequestMapping("saveData.do")
    public void saveData(${ClassName}Entity ${className}Entity, HttpServletRequest request) {
        ResultBean res = new ResultBean();
        res.setResult("1");
        try {
            ${className}Service.add(${className}Entity);
            res.setMessage("成功");
            res.setData(${className}Entity);
        } catch (Exception e) {
            res.error(e, request);
        }
        printWriter(res);
    }

    /**
     * @Description: 根据ID获取数据
     * @Author: ${author}
     * @Params: [id, request]
     * @Return: void
     * @Date: ${datetime}
     */
    @RequestMapping("getById.do")
    public void getById(String id, HttpServletRequest request) {
        ResultBean res = new ResultBean();
        res.setResult("1");
        try {
            ${ClassName}Entity ${className}Entity = ${className}Service.getById(id);
            res.setMessage("成功");
            res.setData(${className}Entity);
        } catch (Exception e) {
            res.error(e, request);
        }
        printWriter(res);
    }

    /**
     * @Description: 更新数据
     * @Author: ${author}
     * @Params: [${className}Entity, request]
     * @Return: void
     * @Date: ${datetime}
     */
    @RequestMapping("updateData.do")
    public void updateData(${ClassName}Entity ${className}Entity, HttpServletRequest request) {
        ResultBean res = new ResultBean();
        res.setResult("1");
        try {
            ${className}Service.update(${className}Entity);
            res.setMessage("成功");
            res.setData(${className}Entity);
        } catch (Exception e) {
            res.error(e, request);
        }
        printWriter(res);
    }

    /**
     * @Description: 删除数据
     * @Author: ${author}
     * @Params: [ids, request]
     * @Return: void
     * @Date: ${datetime}
     */
    @RequestMapping("deleteData.do")
    public void deleteData(String ids, HttpServletRequest request) {
        ResultBean res = new ResultBean();
        res.setResult("1");
        try {
            //（把要删除的数据是否可用设置为0不可用）
            ${className}Service.deleteByIdArray(ids.split(","));
            res.setMessage("成功");
        } catch (Exception e) {
            res.error(e, request);
        }
        printWriter(res);
    }

    /**
     * @Description: 分页查询
     * @Author: ${author}
     * @Params: [page, request]
     * @Return: void
     * @Date: ${datetime}
     */
    @RequestMapping("listPage.do")
    public void listPage(Page page, HttpServletRequest request) {
        ResultBean res = new ResultBean();
        res.setResult("1");
        page.intPageForList(request);
        page.getPd().put("orderBy", "create_Time desc, id desc");
        try {
            ${className}Service.getListPage(page);
            res.setMessage("成功");
            res.setData(page);
        } catch (Exception e) {
            res.error(e, request);
        }
        printWriter(res);
    }
}
